﻿///***************************************************************
/// 시  스  템 : Updms.Cfg
/// 단위시스템 : CFG
/// 계      층 : Presentation Layer
/// 프로그램명 : Cfg2010r
/// 파  일  명 : Cfg2010r.aspx.cs
/// 설      명 : 통합검색
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2014-01-16 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Collections;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Adapter;
using SMFramework.Data;
using SMFramework.Security;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.SMGridView;

using Base.Dac;
using Updms.Common.BaseClass;
using Updms.Com.Exe;
using Updms.Cfg.Exe;


namespace Updms.Cfg
{
	public partial class Cfg2010r : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Cfg2010r";
		public static readonly string gs_path_info = "/updms/Cfg/" + PID + ".aspx";

		Global global = new Global();
		Crypto crypto = new Crypto();

		//검색
		protected string kw1 = "";	//키워드
		protected string kw2 = "";	//분류

		//메뉴 선택값
		protected string gs_sm = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetPgmClass();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetClientScript

		private void SetClientScript()
		{
			//엔터검색
			txt_search_keyword.Attributes.Add("onkeypress", "enterSearchOnPage(event)");
		}

		#endregion

		#region SetInit, SetSearchParameter

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";

			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))
					{
						kw1 = txt_search_keyword.Text.Trim();
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						txt_search_keyword.Text = kw1;
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw2"]))
					{
						kw2 = WebControlUtil.GetCheckBoxListValue(cbl_search_pgm_class, 1);
					}
					else
					{
						kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_pgm_class, kw2);
					}

					break;
				case "SEARCH":
					kw1 = String.IsNullOrEmpty(txt_search_keyword.Text.Trim()) ? "" : txt_search_keyword.Text.Trim();
					kw2 = WebControlUtil.GetCheckBoxListValue(cbl_search_pgm_class, 1);
					break;
			}
		}

		//검색키워드
		private void ShowKeywordLabel()
		{
			string ls_kw2 = WebControlUtil.GetCheckBoxListText(cbl_search_pgm_class, 1);

			lbl_search_keyword.Text = kw1 + " / " + ls_kw2;
		}

		#endregion

		#region 마스터 Method (SetPgmClass)

		//프로그램구분
		private void SetPgmClass()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			lo_dp.AddProperty("ls_user_id", typeof(string), USER_ID);
			lo_dp.AddProperty("ls_access_level", typeof(string), ACCESS_LEVEL);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			Com1011m_NT _Com1011m_NT = new Com1011m_NT();

			lo_ds.Merge(_Com1011m_NT.GetPgmClassByAccessLevel(lo_dp));

			cbl_search_pgm_class.Items.Clear();
			cbl_search_pgm_class.DataSource = lo_ds;
			cbl_search_pgm_class.DataMember = "UPDMS_COM_PGM";
			cbl_search_pgm_class.DataTextField = "Pgm_Nm";
			cbl_search_pgm_class.DataValueField = "Pgm_Class";
			cbl_search_pgm_class.DataBind();

			if (cbl_search_pgm_class.Items.Count > 0)
			{
				for (int i = 0; i < cbl_search_pgm_class.Items.Count; i++)
				{
					cbl_search_pgm_class.Items[i].Selected = true;
				}
			}
		}

		#endregion

		#region 리스트 (SearchProcess)

		//검색
		private void SearchProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();

			//검색
			lo_dp.AddProperty("ls_user_id", typeof(string), USER_ID);
			lo_dp.AddProperty("ls_access_level", typeof(string), ACCESS_LEVEL);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);
			lo_dp.AddProperty("ls_keyword", typeof(string), kw1);
			lo_dp.AddProperty("ls_pgm_classes", typeof(string), kw2);

			using (Cfg2010r_NT _Cfg2010r_NT = new Cfg2010r_NT())
			{
				lo_ds.Merge(_Cfg2010r_NT.SelectProcess(lo_dp));
			}

			GridView1.DataSource = lo_ds;
			GridView1.DataBind();

			//결과출력(키워드, 검색행수)
			ShowKeywordLabel();
			lbl_result_count.Text = DataSetUtil.GetRowCount(lo_ds, "UPDMS_CFG_INTEGRATED_SEARCH").ToString("#,###,##0");
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
				}
			}
			ChangePageMode();
		}

		//ChangePageMode
		private void ChangePageMode()
		{
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region GridView이벤트

		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onMouseOver", GRID_ONMOUSEOVER_COLOR);
				e.Row.Attributes.Add("onMouseOut", GRID_ONMOUSEOUT_COLOR);

				e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();	//번호
			}

			//머지
			SMGridView sGv = new SMGridView(this.Page, ref GridView1);
			sGv.RowSpanGridView(GridView1, 1);//1.Pgm_Class_Nm
			sGv.RowSpanGridView(GridView1, 2);//2.Pgm_Nm
		}

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}

		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			//검색
			lo_dp.AddProperty("ls_user_id", typeof(string), USER_ID);
			lo_dp.AddProperty("ls_access_level", typeof(string), ACCESS_LEVEL);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);
			lo_dp.AddProperty("ls_keyword", typeof(string), kw1);
			lo_dp.AddProperty("ls_pgm_classes", typeof(string), kw2);

			using (Cfg2010r_NT _Cfg2010r_NT = new Cfg2010r_NT())
			{
				lo_ds.Merge(_Cfg2010r_NT.SelectProcess(lo_dp));
			}

			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
		}

		#endregion

	}
}
